<?php
    // This is used to delete a comment from the db.
    // INPUT: $_POST[]
    //
    // OUTPUT: Return text passed (encoded via htmlspecialchars)
    // SIDE EFFECT: Delete record from db.


    require_once("../../../includes.php");

    require_once("../model/comment.php");

    if ( !isloggedin() ) {
        trigger_error('You must be logged in to use this page', E_USER_ERROR);
    }

    // Orienting data
    $ident = intval( required_param('ident' ) );

    $comment = folio_comment::SelectWhereIdent( $ident );
    if ( $comment == false )
        trigger_error('Invalid ident ' . $ident . ' passed to comment_delete.php',
                    E_USER_ERROR);

    // Validate permissions
    $page = folio_page::SelectWherePageIdent( $comment->object_id );

    if ( !$page->Permission('update') ) {
        trigger_error('You do not have permission to delete a comment for this page',
                      E_USER_ERROR);
    }

    if ( folio_comment::Delete( $comment ) ) {
        // Successfull
        header('Location: ' . url . 'mod/folio/html/page_redirection.php?page_ident=' .
                $page->page_ident );
         echo 'Comment Deleted';
    } else {
        // Failure
        echo 'Error: Unable to delete comment ' . $ident ;
    }
?>
